#!/bin/bash
. config
. function

APACHE_PID=`pgrep -o httpd`
TOMCAT_PID=`ps axww | grep catalina.home | grep -v 'grep' | sed q | awk '{print $1}'`

#apache_log_tagging=$"[${DATATIME}] [neo] script"
#tomcat_log_tagging=$"INFO: neo ${DATATIME}"
#echo ${apache_log_tagging} >> ${APACHE_ERROR_LOG}
#echo ${tomcat_log_tagging} >> ${TOMCAT_LOG}
#
#line=`grep -n "\[${DATATIME}\] \[neo\] script" ${APACHE_ERROR_LOG} | awk -F ':' '{print $1}'`
#echo $line
#/etc/init.d/www restart
#sed "1,${line}d" ${APACHE_ERROR_LOG} | grep 'error'

APACHE_LISTEN_COUNT=`netstat -alp | grep '*:http' | wc -l`
TOMCAT_LISTEN_COUNT=`netstat -alp | grep '*:webcache' | wc -l`
DBCONN_ESTABLISHED=`netstat -a | grep ':3433' | wc -l`


# Debug
log "debug" "APACHE_HOME: ${APACHE_HOME}, APACHE_PID: ${APACHE_PID}"
log "debug" "APACHE_HOME: ${TOMCAT_HOME}, APACHE_PID: ${TOMCAT_PID}"

log "debug" "APACHE_LISTEN_COUNT: ${APACHE_LISTEN_COUNT}"
log "debug" "TOMCAT_LISTEN_COUNT: ${TOMCAT_LISTEN_COUNT}"
log "debug" "DBCONN_ESTABLISHED: ${DBCONN_ESTABLISHED}"

log 'debug' "APACHE_MONITOR: ${APACHE_MONITOR}"
log 'debug' "TOMCAT_MONITOR: ${TOMCAT_MONITOR}"
#log 'debug' "DBCONN_MONITOR: ${DBCONN_MONITOR}"

